package com.mdx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mdx.bean.BlightBean;
import com.mdx.service.IBlightService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 虫害
 */
@RestController
@RequestMapping("blight")
public class BlightController {
    @Resource
    private IBlightService blightService;

    //显示所有虫害
    @RequestMapping("/findAllBlight")
    public IPage<BlightBean> findAllBlight(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                         @RequestParam(value = "pageSize", defaultValue = "2") int pageSize) {
        return blightService.findByNameHost(pageNO,pageSize,null,null);
    }

    //添加新虫害
    @RequestMapping("/addBlight")
    public String addBlight(BlightBean blightBean) {
        blightService.save(blightBean);
        return "ok";
    }


    //查看详细信息
    @RequestMapping("/findById")
    public BlightBean findById(int blightId) {
        return blightService.getById(blightId);
    }

    //模糊查询
    @RequestMapping("/findByName")
    public IPage<BlightBean> findByName(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                    @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                    String blightName, String host) {
        return blightService.findByNameHost(pageNO,pageSize,blightName,host);
    }
}
